package wqh.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import wqh.domain.Sensor;

import java.util.List;

/**
 * Created by devts on 2016/9/26.
 */
public interface SensorDao {

    @Select("select * from sensor")
    List<Sensor> findAllRecord();

    String findNameByID(Integer id);

    @Select("select * from sensor where id = #{1}")
    Sensor findAllByID(Integer id);

    @Insert("INSERT INTO sensor (name, detail, type, picture, description, parent_id,level) VALUES(#{name}, #{detail}, #{type},#{picture}, #{description}, #{parent_id}, #{level})")
    int insertRecord(Sensor sensor);

    @Update("UPDATE sensor SET name = #{name}, detail = #{detail}, type = #{type},picture = #{picture}, description = #{description}, parent_id = #{parent_id}, level = #{level} WHERE id = #{id}")
    int updateRecord(Sensor sensor);

    @Delete("DELETE FROM sensor WHERE id = #{1}")
    int deleteRecord(Integer id);

    @Insert("INSERT INTO sensor(name, type) VALUES(#{0}, #{1})")
    int insertRecordSample(String name, Integer type);

    @Insert("INSERT INTO sensor(name, parent_id, level) VALUES(#{name}, #{parent_id}, #{level})")
    int insertRecordOld(Sensor sensor);

    @Update("UPDATE sensor SET name = #{name}, parent_id = #{parent_id}, level = #{level} WHERE id = #{id}")
    int updateRecordOld(Sensor sensor);

    @Update("UPDATE sensor SET name = #{0} WHERE id = #{1}")
    int updateNameById(String name, Integer id);
}
